package com.ddwl.message.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.common.util.UUIDGenerator;
import com.ddwl.message.service.FeedbackService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.message.FeedbackBo;
import com.ddwl.schema.bo.message.FeedbackSearchBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.message.FeedbackVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author Fu Zhaohui
 * @date 2017/1/3
 */
@Api(tags = "在线反馈服务")
@RequestMapping("/feedback")
@RestController
public class FeedbackController extends BaseController {

    @Autowired
    private FeedbackService feedbackService;

    @ApiOperation("保存反馈")
    @Auth(product = {BaseEnum.ProductEnum.ZHENYU, BaseEnum.ProductEnum.CLOTHES, BaseEnum.ProductEnum.MALL})
    @PostMapping("/save")
    public RestVo save(@ApiParam(value = "反馈对象", required = true) @Valid @RequestBody FeedbackBo bo) {
        bo.setUserId(getUserId());
        bo.setProduct(getProduct());
        feedbackService.save(bo);
        return RestVo.ok();
    }

    @PostMapping("page")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @ApiOperation("分页查询反馈")
    public RestVo<PageVo<FeedbackVo>> page(@Valid @RequestBody PageBo<FeedbackSearchBo> pageBo) {
        return RestVo.ok(feedbackService.page(pageBo));
    }

    @ApiOperation("解决")
    @Auth(product = BaseEnum.ProductEnum.CONSOLE)
    @PostMapping("/resolve")
    public RestVo resolve(@ApiParam(value = "反馈对象", required = true) @Valid @RequestBody FeedbackBo bo) {
        bo.setUserId(getUserId());
        feedbackService.resolve(bo);
        return RestVo.ok();
    }
}
